package com.ftg.learn.lesson5;

import java.util.Arrays;

/**
 * learn string
 *
 * @author kangjx
 * @version 1.0
 * @date 2023/6/25 上午8:13
 */
public class String01 {

    //chongzai :

    public String01() {

    }

    public String01(int x) {

    }

//    java se [1 base 2oo 3 datastrutct]

    public static void huiwenshu(int num) {
        // String "abc"
        String a1 = "abc";
        a1 = "def";
        System.out.println();
        String str = num + "";
        //no change
        StringBuilder sBuild = new StringBuilder(str);
        //reverse()
        String newStr = sBuild.reverse().toString();
        System.out.println(str.equals(newStr));
    }

    public static void huiwenshu1(int num) {
        // String "123"
        String str = num + "";

        String newStr = "";
        for (int i = 0; i < str.length(); i++) {
            newStr += str.charAt(str.length() - 1 - i);
        }

        System.out.println(newStr.equals(str));

    }

    //quan jun jiazai null
    public static void main(String[] args) {
        //ding yi
        String str;

        //null
        String str1 = null;

        //empty
        String str2 = "";

        String str3 = new String();

        String str4 = new String("abc");

        String str5 = new String(new char[]{'a', 'b', 'c'}, 1, 2);

        String str6 = new String(new int[]{45, 67, 68}, 1, 2);

        System.out.println("||" + str1 + "||");

        // 2000W shujvtuomin
        String telphone = "15326619037";
        String telNew = telphone.replace("2661", "****");
        System.out.printf("yuan =>%s,new =>%s\n", telphone, telNew);

        String telNew1 = telphone.replace(telphone.substring(3, 7), "****");
        System.out.println(telNew1);

        System.out.println(telphone.substring(0, 3) + "****" + telphone.substring(7));


        //张颂文和张译高下立判，两人被传有矛盾，网友称王不见王难相聚张颂文和张译高下立判，两人被传有矛盾，网友称王不见王难相聚张颂文和张译高下立判，两人被传有矛盾，网友称王不见王难相聚

        //1 .....
        String str7 = "abcabcabcabc";
        System.out.println(str7.indexOf("ab"));
        System.out.println(str7.indexOf("ab", 2 + 0));
        System.out.println(str7.indexOf("ab", 2 + 3));
        System.out.println(str7.lastIndexOf("ab"));

        int num = 0;
        for (int i = str7.indexOf("ab"); i != -1; i = str7.indexOf("ab", "ab".length() + i)) {
            num++;
            System.out.println(i);
        }
        System.out.println("gong" + num);

        int num1 = 0;
        for (int i = 0; i < str7.length(); ) {
            int pos = str7.indexOf("ab", i);
            if (pos != -1) {
                num1++;
                i = pos + 2;
            } else {
                break;
            }
        }
        System.out.println(num1 + "===>");


        int num2 = 0;
        int position = 0;
        while (position != -1) {
            position = str7.indexOf("ab", position);
            if (position != -1) {
                num2++;
                position += "ab".length();
            }
        }
        System.out.println(num2);


        int num3 = 0;
        int position1 = 0;
        while ((position1 = str7.indexOf("ab", position1)) != -1) {
            num3++;
            position1 += "ab".length();
        }

        System.out.println(num3);
        //2 .....
        //3 .....

        //Arrays.fill(a,7);

        //substring() 截取
        //indexof 寻找对应的子串的下标
        //replace 替换

        String string01 = String.join("-", "康", "加", "修");
        String string02 = String.join("-", new String[]{"康", "加", "修"});
        String string03 = String.join("", "康加修".split(""));
        System.out.println(string01);
        System.out.println(string02);
        System.out.println(string03);

        //split 分割
//        "xxxx".split("")
//        "2023-06-25".split("-")
        String[] dates = "2023-06-25".split("-");

        for (String s : dates) {
            System.out.println(s);
        }

        System.out.println(Arrays.toString(dates));
        System.out.println(Arrays.toString("abcdfdsafds".split("")));

        String[] abc = new String[]{"abc", "def", "xyz"};
        System.out.println(String.join(",", abc));

        int[] arr = {1,2,3};
        String[] arr1 = new String[3];
        for (int i = 0; i < arr.length; i++) {
            arr1[i] = String.valueOf(arr[i]);
        }

        System.out.println(Arrays.toString(arr1));

        System.out.println(String.join(",", String.valueOf(1),String.valueOf(2),String.valueOf(3)));

        //是否有办法把一个整数转成字符串
//        1
        System.out.println(1 + "");
        //String.valueOf 把对应的基础类转换成为string
//        System.out.println(String.valueOf(1));
    }


}
